#coding:utf8
# partitionBy可以对分区规则自定义
from pyspark import SparkContext,SparkConf

if __name__ == '__main__':
    conf = SparkConf().setAppName("test").setMaster("local[*]")
    sc = SparkContext(conf=conf)

    rdd = sc.parallelize([("a",1),("b",2),("c",3),("a",2),("b",3),("c",4)])

    def process(x):
        if 'a'==x:return 0
        if 'a' == x: return 1
        return 2

    # numPartitions：分区数量
    # partitionFunc：分区函数，输入的是K，返回的是int
    print(rdd.partitionBy(numPartitions=3, partitionFunc=process).glom().collect())